package run;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;
import java.util.Scanner;

import command.ParseCommandImpl;
import action.DataProcessAction;
import pojo.Customer;
import processor.impl.DataProcessorImpl;
import scanner.DataScanner;
import scanner.impl.DataScannerImpl;

public class Run {
	
	public void run() throws IOException{
		DataScanner scanner=new DataScannerImpl(new FileInputStream("data.txt"));
		List<Customer> list=scanner.scann();
		ServerSocket server = new ServerSocket(9994);
		Socket socket=server.accept();
		System.out.println("continue...");
		DataProcessAction ac=new DataProcessAction();
		DataOutputStream out=new DataOutputStream(socket.getOutputStream());
		InputStream in=socket.getInputStream();
		out.write("Who are you?\n".getBytes());	
		BufferedReader reader=new BufferedReader(new InputStreamReader(in));	
		ParseCommandImpl pci=new ParseCommandImpl(list, out);
		String name=reader.readLine();
		while (pci.command(name)) {
			name=reader.readLine();
		}
		out.close();
		reader.close();
		socket.close();
		server.close();
	}
	public static void main(String[] args) throws IOException {
		new Run().run();

	}
}
